﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="spring" uri="/WEB-INF/lib/spring.tld"%>
<%String title="操作${table.TableMemo}";%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title><%=title%></title>
    <%@include file="../../include/jsAndCss.jsp" %>
    <script type="text/javascript">
	/*添加或修改数据*/
var ActionUrl =adminUrl+"${table.TableNameAlias}/";
var editId = 0;
jQuery(function () {
    editId = GetRequest()["id"];
    initPage();
	if (editId > 0) {
        loadData();
    }
});
/**
 *保存修改的数据
 */
function saveOrUpdate() {
    var param = jQuery("#form1").serialize();
    var methodName = editId > 0 ? "Edit" : "Add";
    commonBO.saveOrUpdate(methodName,param);
}

#foreach($c in $ColumnList)
	#if($c.IsPrimary)
	#set ($primaryKey=$c.ColumnNameAlias)
	#end
#end
/*初始化页面数据*/
function loadData() {
 var param={"${primaryKey}":editId};
jQuery.ajax({
	url: ActionUrl+"View"+admExtension,
	data: param,
	type:"post",
	dataType: "json",
        success: function (result) {
            if (result.status == "SUCCESS") {
#foreach($c in $ColumnList)
#if($c.IsPrimary)
jQuery("#hd${c.ColumnNameAlias}").val(result.data.${Utils.ToTitleLower($c.ColumnNameAlias)});
#elseif($c.ColumnType=="Integer")
#if($c.ColumnName=="Status")
SetRadioChecked("Status",result.data.status);
#else
jQuery("#txt${c.ColumnNameAlias}").numberspinner("setValue",result.data.${Utils.ToTitleLower($c.ColumnNameAlias)});
#end
#elseif($c.ColumnType=="Date")
 #if($c.ColumnName!="Update_Date"&&$c.ColumnName!="Create_Date")
jQuery("#txt${c.ColumnNameAlias}").datetimebox("setValue",result.data.${Utils.ToTitleLower($c.ColumnNameAlias)});
 #end
#else
jQuery("#txt${c.ColumnNameAlias}").val(result.data.${Utils.ToTitleLower($c.ColumnNameAlias)});
#end
#end
	}
	else
	{
		 commonBO.alertError(result);
	}
   },
    error: function () {
    jQuery.messager.alert('操作提醒', "操作失败，请查看错误日志或联系管理员！", 'error');
    }
	});
 }

 /*返回列表页*/
 function  backToList()
 {
     location.href="list.jsp";
 }
 /*初始化页面*/
function initPage() {
    commonBO.getEnumDictionary("StatusSpan", "radio", "SwitchStatus", "Status",	0);
}
	
	</script>
</head>
<body>
<!--修改窗口-->
<div id="Win" class="easyui-window" title="<%=title%>" data-options="closed: false,closable:false,modal: true,resizable: true,minimizable: false,
        maximizable: true,maximized:false,collapsible: false" style="width: 550px; height: 400px; padding: 10px;">
    <div class="easyui-layout" data-options="fit:true">
        <form id="form1">
            <div data-options="region:'center'" style="padding: 10px;">
                <table align="center">
				#foreach($c in $ColumnList)
				#if($c.IsPrimary)
					<input type="hidden"  id="hd${c.ColumnNameAlias}" name="${c.ColumnNameAlias}" value="0"/>
				#elseif($c.ColumnType=="Date")
				    #if(($c.ColumnName!="Update_Date")&&($c.ColumnName!="Create_Date"))
					 <tr><td class="tdright">
                        <spring:message code="${c.ColumnNameAlias}"/>
                        ：</td>
                        <td>
                            <input type="text" id="txt${c.ColumnNameAlias}" name="${c.ColumnNameAlias}" class="easyui-datetimebox inputwidth" required="true"
                                   style="width: 120px;" data-options="editable:false"/>
                        </td></tr>
				    #end
				#elseif($c.ColumnType=="Integer")
					#if($c.ColumnName=="Status")
					 <tr><td class="tdright">
                        <spring:message code="${c.ColumnNameAlias}"/>
                        ：</td>
                        <td>
                           <span id="StatusSpan"></span>
                        </td></tr>
					#else
				       <tr><td class="tdright">
                        <spring:message code="${c.ColumnNameAlias}"/>
                        ：</td>
                        <td>
                            <input type="text" id="txt${c.ColumnNameAlias}" name="${c.ColumnNameAlias}" class="easyui-numberspinner inputwidth" required="true"
                                   style="width: 120px;"  data-options="value:1,min:0"/>
                        </td></tr>
					#end
				#elseif($c.ColumnType=="String")
                    <tr><td class="tdright">
                        <spring:message code="${c.ColumnNameAlias}"/>
                        ：</td>
                        <td>
                            <input type="text" id="txt${c.ColumnNameAlias}" name="${c.ColumnNameAlias}" class="easyui-validatebox inputwidth" required="true"
                                   style="width: 220px;" validType="length[0,${c.ColumnMaxLen}]"/>
                        </td></tr>
				#else
				  <tr><td class="tdright">
                        <spring:message code="${c.ColumnNameAlias}"/>
                        ：</td>
                        <td>
                            <input type="text" id="txt${c.ColumnNameAlias}" name="${c.ColumnNameAlias}" class="easyui-validatebox inputwidth" required="true"
                                   style="width: 220px;"/>
                        </td></tr>
				#end
				#end
                </table>
            </div>
            <div data-options="region:'south',border:false" style="text-align: right; padding: 5px 0 0;">
                <a class="easyui-linkbutton" onclick='saveOrUpdate()' id="btnSave" data-options="iconCls:'icon-ok'" href="javascript:void(0)"
                        >确定</a> <a class="easyui-linkbutton" data-options="iconCls:'icon-undo'"
                                   href="javascript:void(0)" onclick='backToList()' id="btnBack">返回</a>
            </div>
        </form>
    </div>
</div>
</body>
</html>